#!/bin/bash

cd $(dirname $(readlink -f $0))/../



function xx() {

    clang_format=$(find ~/.vscode-server/ -name "clang-format" | head -n 1)

    if [[ -z $clang_format ]];then
        clang_format=$(which clang-format)
        if [[ -z "$clang_format" ]];then
            echo "can't find clang-format"
            exit -1
        fi
    fi

    echo $@
    $clang_format -style=file   -fallback-style=google --Wno-error=unknown -i $@
}
export -f xx

#find . -regex '.*\.\(cpp\|hpp\|cc\|c\|h\|cxx\)' -exec $clang_format -style=file -i {} \;
find ./src -regex '.*\.\(cpp\|hpp\|cc\|c\|h\|cxx\)' -exec bash -c 'xx "$@"' bash  {} \;

